package com.perre.cms;

import java.io.StringReader;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.validation.Validate;

/**
 * The Class TestAction.
 */
@UrlBinding("/Test.action")
public class TestAction implements ActionBean {

	/** The context. */
	private ActionBeanContext context;

	/** The number one. */
	@Validate(required = true)
	private double numberOne;

	/** The number two. */
	@Validate(required = true)
	private double numberTwo;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ActionBeanContext getContext() {
		return context;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setContext(final ActionBeanContext context) {
		this.context = context;
	}

	/**
	 * Adds the.
	 * 
	 * @return the resolution
	 */
	@DefaultHandler
	public Resolution add() {
		final String result = String.valueOf(numberOne + numberTwo);
		return new StreamingResolution("text", new StringReader(result));
	}

	/**
	 * Divide.
	 * 
	 * @return the resolution
	 */
	public Resolution divide() {
		final String result = String.valueOf(numberOne / numberTwo);
		return new StreamingResolution("text", new StringReader(result));
	}

	// Standard getter and setter methods
	/**
	 * Gets the number one.
	 * 
	 * @return the number one
	 */
	public double getNumberOne() {
		return numberOne;
	}

	/**
	 * Sets the number one.
	 * 
	 * @param numberOne
	 *            the new number one
	 */
	public void setNumberOne(final double numberOne) {
		this.numberOne = numberOne;
	}

	/**
	 * Gets the number two.
	 * 
	 * @return the number two
	 */
	public double getNumberTwo() {
		return numberTwo;
	}

	/**
	 * Sets the number two.
	 * 
	 * @param numberTwo
	 *            the new number two
	 */
	public void setNumberTwo(final double numberTwo) {
		this.numberTwo = numberTwo;
	}

}
